//
//  MoneyBackOrderViewController.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/9.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//


#import "MoneyBackOrderViewController.h"
#import "BkMoneyBackOrderView.h"
#import "CommitSucessViewController.h"
#import "LXRequstOrderDetailModel.h"
@interface MoneyBackOrderViewController ()
@property (nonatomic,strong) BkMoneyBackOrderView *headerView;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) LXRequstOrderDetailModel *model;
@end

@implementation MoneyBackOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self.tableView.mj_header beginRefreshing];
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(TSScaleW(0), 0, TSScreenWidth, TSScreenHeight - Height_NavBar) style:(UITableViewStyleGrouped)];
        
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        _tableView.tableHeaderView = self.headerView;
        if (@available(iOS 11.0, *))
        {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _tableView.estimatedRowHeight = 0;
            _tableView.estimatedSectionHeaderHeight = 0;
            _tableView.estimatedSectionFooterHeight = 0;
        }
        else
        {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        WS(weakSelf);
        _tableView.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
            [weakSelf requstDetailDataRequst];
        }];
    }
    return _tableView;
}

-(BkMoneyBackOrderView *)headerView{
    if (!_headerView) {
        _headerView = [[BkMoneyBackOrderView alloc]init];
        WS(weakSelf);
        _headerView.gotoServerBlcok = ^{
            //[weakSelf gotoWebWithUrl:kKefuServerUrl title:@"我的客服"];
            [weakSelf userInforRequstGetbuttonsAction];
        };
    }
    return _headerView;
}
//        [self.navigationController pushViewController:vc animated:YES];
        


-(void)userInforRequstGetbuttonsAction{
    
        [NetWorkTools postConJSONWithUrl:@"getbuttons" parameters:@{} success:^(id responseObject) {
            NSString *result = responseObject[@"result"];
            NSString *resultNote = responseObject[@"resultNote"];
            NSString *datastr = responseObject[@"datastr"];
            NSString *url  = kKefuServerUrl;
            if ([result integerValue] == 0) {
                if ( [datastr integerValue] == 0) {
                    url = kKefuServerUrl;
                }else{
                    url = kSelfServerUrl;
                }
                [self gotoWebWithUrl:url title:@"我的客服"];
            }else{
                 [MBProgressHUD showError:resultNote];
            }
                         
        } fail:^(NSError *error) {
            
        }];
}
-(void)requstDetailDataRequst{
    //kMyservicestodetailUrl
    NSDictionary *pamas = @{@"ordernum":_ordernum};

          [NetWorkTools postConJSONWithUrl:@"myorderdetail" parameters:pamas success:^(id responseObject) {
              NSString *result = responseObject[@"result"];
              NSString *resultNote = responseObject[@"resultNote"];
              NSDictionary *data = responseObject[@"dataobject"];

              if (result.integerValue == 0) {
                  LXRequstOrderDetailModel *model = [[LXRequstOrderDetailModel alloc]init];
                  [model setValuesForKeysWithDictionary:data];
                  self.model = model;
              }else{
                   [MBProgressHUD showError:resultNote];
              }
         [self.tableView.mj_header endRefreshing];
          } fail:^(NSError *error) {
         [self.tableView.mj_header endRefreshing];
          }];
}
-(void)setModel:(LXRequstOrderDetailModel *)model{
    _model = model;
    _headerView.model = _model;
    _tableView.tableHeaderView = self.headerView;
    NSInteger index = 0;
    for (NSDictionary *dic in _model.ordertailList) {
        index += [dic[@"gnum"] integerValue];
    }
    _headerView.amount = index;
}

@end
